package com.yc.cinema;

import com.yc.cinema.bean.User;
import com.yc.cinema.biz.MovieBiz;
import com.yc.cinema.dao.BaseDao;
import com.yc.cinema.dao.UserDao;
import org.springframework.context.annotation.*;

import java.util.ArrayList;
import java.util.List;

// Spring 配置类注解  ==> beans.xml
@Configuration
// 组件扫描, 扫描该包及其子包
@ComponentScan({"com.yc.cinema"})
public class AnnoConfig {

    @Bean("hello")
    HelloBean hello(){
        return new HelloBean();
    }

    @Bean("hello1")
    HelloBean hello1(){
        return HelloBean.create();
    }

    @Bean("hello2")
    // 接口注入 hello1
    HelloBean hello2( HelloBean hello1 ){
        return hello1.newInstance();
    }

    @Bean("hello3")
    @Scope("prototype")
    @Primary
    HelloBean hello3(){
        final HelloBean helloBean = new HelloBean();
        helloBean.setName("主 Bean");
        return helloBean;
    }

    @Bean(value = "hello4",
            initMethod = "init",
            destroyMethod = "gameOver")
    @Lazy
    HelloBean hello4(){
        final HelloBean helloBean = new HelloBean();
        helloBean.setName("李四");
        helloBean.setAge(20);
        List list = new ArrayList();
        list.add("王五");
        list.add("赵六");
        list.add(null);
        list.add("XXX");
        helloBean.setFriends(list);
        return helloBean;
    }

    @Bean
    @Primary
    BaseDao<Object> uDao(){
        return new UserDao();
    }

    @Bean("mbiz")
    @Primary
    MovieBiz movieBiz(){
        return new MovieBiz();
    }
}
